<%@ page language="java" contentType="text/html;charset=UTF-8"%>
<%@ include file="/commons/taglibs.jsp"%>
<%@ include file="/commons/messages.jsp"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>修改住房信息&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</title>
<script language="JavaScript" type="text/javascript" src=".${ctx}/scripts/public.js"></script>
<link href="${ctx}/styles/public.css" rel="stylesheet" type="text/css">
<link href="${ctx}/styles/listTable.css" rel="stylesheet" type="text/css">
<link href="${ctx}/styles/aux_window.css" rel="stylesheet" type="text/css">

<script language="JavaScript" type="text/javascript" src="${ctx}/scripts/public.js"></script>
<script language="JavaScript" type="text/javascript" src="${ctx}/scripts/show.js"></script>
<script language="JavaScript" type="text/javascript" src="${ctx}/scripts/common/prototype.js"></script>
<script language="javascript" src="${ctx}/scripts/div/window.js"></script>
<script language="JavaScript" type="text/javascript" src="${ctx}/scripts/div/common.js"></script>
<link href="${ctx}/styles/validation/style.css" rel="stylesheet" type="text/css">
<script language="JavaScript" type="text/javascript" src="${ctx}/scripts/validation/validation.js"></script>
<script language="JavaScript" type="text/javascript" src="${ctx}/scripts/validation/effects.js"></script>
<script type="text/javascript">
	var submitFlag = true;/***表单验证是否通过验证***/
	var bank = null; //银行相关操作
	function submitForm(){
		if(submitFlag){
		var flag = document.getElementById("ownerHouseForm").fireEvent("onSubmit");
			if(flag){
				var str = $("ownerHouseForm").serialize();
				//当房间处在出盘状态时  银行信息是不可以修改的  所以这里添上其值
				if($('bankAccoutEditMessageDIV').style.display == "inline"){
					str += "&bankId=" + $("bankId").value;
					str += "&bankNumber=" + $("bankNumber").value;
					str += "&accountOwner=" + $("accountOwner").value;
					str += "&contactNumber=" + $("contactNumber").value;
				}
				var action = "${ctx}/customer_ownerAction.do?method=editOwnerHouseCache";
				var myAjax = new Ajax.Request(action,
		                   {method: 'post', parameters: str, onComplete: closeFrm}
		                   );
	        }
        }
	}
	/************验证合同号、房产证号在系统中唯一******************/
	function setSubmitFlag(result){
		 var obj= result.responseText;
		 if(obj != 'true'){
		 	validationAlert(inputFlag,true,result.responseText);
		 	submitFlag = false;
		 	return;
		 }
		 submitFlag = true;
	}
	var inputFlag = null; //确定是合同号还是房产证失去焦点
	/****验证合同号****/
	function validationHouseContractNumber(){
		if($F('houseContractNumber') == null || $F('houseContractNumber') =="")
			return;
		inputFlag = "houseContractNumber";
		var url = "${ctx}/customer_ownerAction.do?method=validationHousePropertyContractNumber";
		var parms = "houseNumber=" + $F('houseNumber') + "&houseContractNumber=" + $F('houseContractNumber');
		new Ajax.Request(url,{method: 'post', parameters: parms, onComplete:setSubmitFlag });
	}
	/****验证房产证号*****/
	function validationHousePropertyNo(){
		if($F('housePropertyNo') == null || $F('housePropertyNo') =="")
			return;
		inputFlag = "housePropertyNo";
		var url = "${ctx}/customer_ownerAction.do?method=validationHousePropertyContractNumber";
		var parms = "houseNumber=" + $F('houseNumber') + "&housePropertyNo=" + $F('housePropertyNo');
		new Ajax.Request(url,{method: 'post', parameters: parms, onComplete:setSubmitFlag });
	}

	/**
	 *如果银行帐号处于出盘还没回盘状态 则不能修改
	 */
	function setBankStatus(){
		var url = "${ctx}/customer_ownerAction.do?method=loadHouseContractNumberAndPropertyNo";
		var parm = "houseNumber=${ownerHouse.houseNumber}"
		new Ajax.Request(url,
            {method: 'post', parameters: parm, onComplete: function(result){
            			var parms=eval('(' + result.responseText + ')');
						//设置状态
						//parms.isIn ture时表示不存在未回盘的数据,false标识存在未回盘的数据,在这里只要存在未回盘的,则帐号不能修改
						var flag = eval(parms.isIn);//帐号是否已出盘标识,ture表示没出盘记录,false表示有出盘记录
						if(flag){//没有出盘记录,判断银行名称是否有值,如果有值,则相应输入框可用,否则不可用
							flag = flag && (parms.bankId != null && parms.bankId != "");
							bank.setStatuz(flag);
							if(!flag){//如果没有值时,需要对银行名称特殊处理下
								$('bankNameSelect').disabled = false;
								$('bankAccoutEditMessageDIV').style.display = "none";
							}
						}else{
							$('bankAccoutEditMessageDIV').style.display = "inline";
							bank.setStatuz(flag);
						}

            }}
            );
	}

//*************银行操作对象*****************///
	//参数说明：银行名称下拉框ID,银行帐号ID、开户人ID、合同号ID
	function Bank(bankName,bankNumber,accountOwner,contactNumber){
		var _bank = null;//自身的引用,这样可以引用其他方法

		var _bankNameObj = $(bankName);//银行名称下拉框
		var _bankNumberObj = $(bankNumber);//银行帐号
		var _accountObj = $(accountOwner);//银行帐号
		var _contactObj = $(contactNumber);//合同号

		var _require = "aux_intable_require";//必选样式
		var _notRequire  = "aux_intable_td2";//不必选样式

		this.init = function(abank){
			_bank = abank;
		}
		//填充各框的输入值,银行名称给定一个银行ID,显示对应银行名称
		this.fill = function(bankId,bankNumber,accountOwner,contactNumber){
			_setBankName(bankId);
			_bankNumberObj.value = bankNumber;
			_accountObj.value = accountOwner;
			_contactObj.value = contactNumber;
		}
		//设置各输入东东状态, true代表可用,false代表不可用
		this.setStatuz = function(flag){
			_bankNameObj.disabled = !flag;
			_bankNumberObj.disabled = !flag;
			_accountObj.disabled = !flag;
			_contactObj.disabled = !flag;
		}
		//银行名称下拉框onchange处理事件
		this.bankNameEventHandle = function(selectedIndex){
			var flag = selectedIndex != 0;
			if(flag){
				_bankNameObj.parentNode.className = _require;

				_bankNumberObj.parentNode.className = _require;
				Validation.changeElmValidate(_bankNumberObj.id,"inputtext required");

				_accountObj.parentNode.className = _require;
				Validation.changeElmValidate(_accountObj.id, "inputtext required");

				_bank.setStatuz(flag);//设置所有的东东可以用
			}else{
				_bankNameObj.parentNode.className = _notRequire;
				_bankNumberObj.parentNode.className = _notRequire;
				Validation.changeElmValidate(_bankNumberObj.id, "inputtext");

				_accountObj.parentNode.className = _notRequire;
				Validation.changeElmValidate(_accountObj.id, "inputtext");

				_bank.setStatuz(flag);//先设置所有的不可用,然后把银行名称下拉框设置回来
				_bankNameObj.disabled = false;
			}
		}

	/***********private method*************/
		//设置银行名称下拉框显示相应银行ID的值
		function _setBankName(bankId){
			var options = _bankNameObj.options;
				for(var i = 0; i < options.length; i++){
					if(options[i].value == bankId){
						_bankNameObj.selectedIndex = i;
						break;
					}
				}
		}
	}
	function closeFrm(){
		findFrame("ownerList").reLoadIframe();
		windowClose();
	}

	function setSelectBackName(thiz){
		if(thiz.selectedIndex == 0 ) {
			document.getElementById("bankName").value = "";
			return;
		}
		var opt = thiz.options[thiz.selectedIndex];
		document.getElementById("bankName").value = opt.text;
	}
	function init(){
		document.getElementById("bankNameSelect").fireEvent("onchange");
		document.getElementById("bankNumber").fireEvent("onblur");

		bank = new Bank('bankNameSelect','bankNumber','accountOwner','contactNumber');
		bank.init(bank);

		$('bankNameSelect').onchange = function(){
										setSelectBackName(this);
										bank.bankNameEventHandle(this.selectedIndex);
									}
		$('bankNameSelect').fireEvent("onchange");
		setBankStatus();

	}
</script>
</head>
<base target="_self">
<body onload="init();">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td class="window_head_outBg"><table border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td><img src="${ctx}/images/ico_Advance.gif" width="16" height="16" align="absmiddle"> <span class="window_head_intext">修改住房信息</span></td>
        </tr>
    </table></td>
  </tr>
  <tr>
    <td class="aux_header_line_1"></td>
  </tr>
  <tr>
    <td class="aux_header_line_2"></td>
  </tr>
  <tr>
    <td class="content"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td class="aux_outtable_color">
		<form id="ownerHouseForm" name="ownerHouseForm" action="${ctx}/customer_ownerAction.do?method=editOwnerHouseCache" method="post"  class="required-validate">
              <input name="houseNumber" type="hidden" value="${ownerHouse.houseNumber}">
			  <input name="houseId" type="hidden" value="${ownerHouse.houseId}">
			  <input name="manageHouseId" type="hidden" value="${ownerHouse.manageHouseId}">
			  <input name="index" type="hidden" value="${ownerHouse.index}">
			   <input id="bankName" name="bankName" type="hidden" value="${ownerHouse.bankName}">
        <table width="100%" border="0" cellpadding="0" cellspacing="1" class="aux_intable_color">
            <tr>
              <td class="aux_intable_td1">房号：</td>
              <td class="aux_intable_td2">${ownerHouse.houseNumber}</td>
            </tr>
            <tr>
              <td class="aux_intable_td1">买卖(预售)合同号：</td>
              <td class="aux_intable_td2"><input id="houseContractNumber" name="houseContractNumber" maxlength="50" type="text" class="inputtext" onblur="validationHouseContractNumber();" value="${ownerHouse.houseContractNumber}" size="16"></td>
            </tr>
            <tr>
              <td class="aux_intable_td1">房产证号：</td>
              <td class="aux_intable_td2"><input id="housePropertyNo" name="housePropertyNo" maxlength="36" type="text" class="inputtext" onblur="validationHousePropertyNo();" value="${ownerHouse.housePropertyNo}" size="16"></td>
            </tr>
            <tr>
              <td class="aux_intable_td1">银行名称：</td>
              <td class="aux_intable_td2">
					<pms:unitedSelect name="bankId"
										id="bankNameSelect"
										dataList="${banklist}"
										optionLabel="bankName"
										optionValue="keyword"
										value="${ownerHouse.bankId}"
										selectText="请选择..."
										>
					</pms:unitedSelect>
					<div id="bankAccoutEditMessageDIV" style="display:none">银行帐号正出盘中不能修改</div>
              </td>
            </tr>
			<tr>
              <td class="aux_intable_td1">银行账号：</td>
              <td class="aux_intable_td2"><input id="bankNumber" name="bankNumber" maxlength="25" type="text" class="inputtext" value="${ownerHouse.bankNumber}" size="16"></td>
            </tr>
			<tr>
              <td class="aux_intable_td1">开户人：</td>
              <td class="aux_intable_td2"><input id="accountOwner" name="accountOwner" maxlength="32" type="text" class="inputtext" value="${ownerHouse.accountOwner}" size="16">               </td>
            </tr>
			<tr>
			  <td class="aux_intable_td1">合同号：</td>
			  <td class="aux_intable_td2"><input id="contactNumber" name="contactNumber" type="text" class="inputtext" value="${ownerHouse.contactNumber}" size="16" maxlength="50"></td>
			</tr>
        </table>
         <input type="submit" id="formSubmit" style="display:none">
       	</form>
       </td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td class="window_footer"><table border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td><table border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td class="buttonOffLeft" id="btn1_21"></td>
              <td class="buttonOffMiddle" id="btn1_22" onClick="submitForm();" onMouseOver="btn_change_over(2)" onMouseOut="btn_change_out(2)" onblur="btn_change(2)"><img src="${ctx}/images/ico_ok.gif" alt="" width="14" height="14" border="0" align="absbottom"> 确 定</td>
              <td class="buttonOffRight" id="btn1_23"></td>
            </tr>
        </table></td>
        <td class="btn_between_space"></td>
        <td><table border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td class="buttonOffLeft" id="btn1_31"></td>
              <td class="buttonOffMiddle" id="btn1_32" onClick="windowClose();" onMouseOver="btn_change_over(3)" onMouseOut="btn_change_out(3)" onblur="btn_change(3)"><img src="${ctx}/images/ico_cancel.gif" alt="" width="14" height="14" border="0" align="absbottom"> 取 消</td>
              <td class="buttonOffRight" id="btn1_33"></td>
            </tr>
        </table></td>
      </tr>
    </table></td>
  </tr>
</table>
</body>
</html>